<?php
header ( "Cache-Control: no-store,no-cache, must-revalidate" );
header ( "Content-Type: text/html; charset=utf-8" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Registrierung</title>
<link href="design/style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="action_formulaire.js"></script>
<script type="text/javascript" src="prototype.js"></script>

</head>

<body>
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . "/bib/class/php/mysql_class.php";
if (isset ( $_POST ['Absenden'] ) && (! empty ( $_POST ['Absenden'] ))) {
	
	$mysql_bib = new mysql_class ( 'vksm.net.mysql', 'vksm_net', 'egDYxATy', 'vksm_net' );
	// $mysql_bib = new mysql_class ( 'localhost', 'root', '', 'regi' );
	
	$pseudo = $_POST ['pseudo'];
	$passwort = $_POST ['passwort'];
	$nachname = $_POST ['nachname'];
	$vorname = $_POST ['vorname'];
	$email = $_POST ['email'];
	$titel = $_POST ['titel'];
	$beruf = $_POST ['beruf'];
	
	// Abfrage, um zu prüfen ob Pseudo schon vorhanden ist.
	$pruefpseudo = $mysql_bib->query ( "SELECT * FROM user WHERE pseudo = '$pseudo'" );
	// Abfrage, um zu prüfen ob Email schon vorhanden ist.
	$pruefemail = $mysql_bib->query ( "SELECT * FROM user WHERE email = '$email'" );
	// Abfrage, um zu prüfen ob Email in regi schon vorhanden ist.
	$data = $mysql_bib->query ( "SELECT email FROM regi WHERE email = '$email'" );
	
	$pruefemailregi = "";
	foreach ( $data as $elt ) {
		$pruefemailregi = $elt ["email"];
	}
	
	if (count ( $pruefpseudo ) == 0 && count ( $pruefemail ) == 0 && $pruefemailregi == $email) {
		
		$salt = $nachname . '.' . $vorname;
		
		$hashed_pwd_salt = crypt ( $passwort, $salt );
		
		$insertMember = array (
				"titel" => $titel,
				"nachname" => $nachname,
				"vorname" => $vorname,
				"email" => $email,
				"pseudo" => $pseudo,
				"passwort" => $hashed_pwd_salt,
				"beruf" => $beruf 
		);
		$idMember = $mysql_bib->insert ( "user", $insertMember );
		session_start ();
		$_SESSION ['login'] = $pseudo;
		
		echo "<script language='javascript'>window.location = 'gallery.php';</script>";
	} 

	else {
		if (count ( $pruefpseudo ) != 0) {
			
			echo '<FONT COLOR = RED>' . "Dieser Pseudo ist leider schon vergeben." . '</FONT>';
		} else if (count ( $pruefemail ) != 0) {
			echo '<FONT COLOR = RED>' . "Diese E-mail Adresse ist leider schon vergeben." . '</FONT>';
		} else {
			echo '<FONT COLOR = RED>' . "Sie haben keinen Zugang auf diese Webseite." . '</FONT>';
		}
		echo '<br/>';
	}
	
	mysql_close ();
}
?>
<form style="width: 700px" name="registration"
		action="registrierung.php" method="post"
		onSubmit="return controleRegistrierung()">
		<fieldset>
			<legend>Registrierung</legend>
			<table width="700px">
				<tr>
					<td class="libelle">Titel<sup>*</sup>:
					</td>
					<td><select id="titel" name="titel">
							<option selected="selected" value="monsieur">Herr</option>
							<option value="madame">Frau</option>
					</select></td>
				</tr>

				<tr>
					<td class="libelle">Nachname<sup>*</sup>:
					</td>
					<td><input type="text" id="nachname" name="nachname" size="20" /></td>
				</tr>

				<tr>
					<td class="libelle">Vorname<sup>*</sup>:
					</td>
					<td><input type="text" id="vorname" name="vorname" size="30" /></td>
				</tr>

				<tr>
					<td class="libelle">Beruf<sup>*</sup>:
					</td>
					<td><select id="cmb_beruf" name="beruf">
							<option>Student (in)</option>
							<option>Berufstätig</option>
							<option>Sonstiges</option>
					</select></td>
				</tr>

				<tr>
					<td class="libelle">Pseudo<sup>*</sup>:
					</td>
					<td><input type="text" id="pseudo" name="pseudo" size="50" /></td>
				</tr>
				<tr>
					<td class="libelle">Passwort<sup>*</sup>:
					</td>
					<td><input type="password" id="passwort" name="passwort" size="50" /></td>
				</tr>
				<tr>
					<td class="libelle">Passwort wiederholen<sup>*</sup>:
					</td>
					<td><input type="password" id="passwortKontrolle"
						name="passwortKontrolle" size="50" /></td>
				</tr>
				<tr>
					<td class="libelle">E-mail<sup>*</sup>:
					</td>
					<td><input type="text" id="email" name="email" size="50" /></td>
				</tr>

				<tr>
					<td class="libelle">E-mail wiederholen<sup>*</sup>:
					</td>
					<td><input type="text" id="emailKontrolle" name="emailKontrolle"
						size="50" /></td>
				</tr>

				<tr>
					<td></td>
					<td><input type="reset" value="Zurücksetzen" id="Zurücksetzen" />
						<input type="submit" onClick="return controleRegistrierung()"
						name="Absenden" value="Absenden" id="Absenden" /></td>					
				</tr>
				<tr>
					<td style="text-align: left"><span><a href="index.php">Anmelden</a></span></td>
					<td style="text-align: right"><span><a href="http://www.vksm.net">Zur
							Webseite des VKSM e.V.</a></span></td>
				</tr>
			</table>

		</fieldset>

	</form>
</body>
</html>
